package com.weipeep.sys.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.weipeep.api.entity.PageBean;
import com.weipeep.api.entity.ResultBean;
import com.weipeep.common.utils.Result;
import com.weipeep.sys.domain.MottoDO;
import com.weipeep.sys.service.MottoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/api")
public class ApiController {
    @Autowired
    private MottoService mottoService;

    @RequestMapping("/page_fetch_user")
    @ResponseBody
    public ResultBean<PageBean> apiFetchUser(int nextPage,int requestCount,int type){
        // 查询列表数据
        Page<MottoDO> page = new Page<>(nextPage, requestCount);
        MottoDO mottoDO = new MottoDO();
        mottoDO.setType(type);
        Wrapper<MottoDO> wrapper = new EntityWrapper<MottoDO>(mottoDO);
        PageBean pageBean = new PageBean();
        page = mottoService.selectPage(page, wrapper);
        int total = mottoService.selectCount(wrapper);
        pageBean.setItems(page.getRecords());
        pageBean.setTotalResults(total);
        pageBean.setNextPage(nextPage+1);
        pageBean.setPrevPage(nextPage-1);
        pageBean.setRequestCount(requestCount);
        pageBean.setResponseCount(page.getRecords().size());

        ResultBean resultBean = new ResultBean();
        resultBean.setCode(1);
        resultBean.setResult(pageBean);
        resultBean.setStatus(1);
        return resultBean;
    }
}
